<?php

namespace app\home\controller;

use think\Db;
use think\Request;
use think\Session;


class Goods extends HomeController
{
	// 商品列表
	public function index()
	{
	    $res = Db::table('xt_goods')->select();
		return $this->assign('res', $res)->fetch('index');
	}

	// 商品详情
	public function goodsDesc()
	{
        $request = Request::instance();
        $id = $request->param('id');
        $data = Db::table('xt_goods_property')->where(['gid'=>$id])->select();
        $res = Db::table('xt_goods')->where(['id'=>$id])->find();
		return $this->assign(['data'=>$data, 'res'=>$res])->fetch('goodsdesc');
	}

	// 单属性查询
    public function proFind($proid)
    {
        $pro = Db::table('xt_goods_property')->where(['id' => $proid])->find();
        if($pro > 0){
            $pro['status'] = true;
        }else{
            $pro['status'] = false;
        }
        return json($pro);
    }

    public function settle($gid){
        
	    $uid = Session::get('uid');

        $data['count'] = input('post.count');
        $data['orderMoney'] = input('post.orderMoney');
        $data['uid'] = $uid;  // 用户id
        $data['gid'] = $gid;  // 商品id
	    $data['proId'] = input('post.proid');  // 商品规格id
	    $data['orderTime'] = date('Y-m-d H:i:s');  // 下单时间

        $res = Db::table('xt_goods_order')->insert($data);

        if($res > 0){
            $info['status'] = true;
            $info['info'] = '下单成功';
        }else{
            $info['status'] = false;
            $info['info'] = '下单失败';
        }
        return json($info);
    }
}